﻿if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
function moveUp(sSelect,isToTop)
 {
     var oSelect = document.getElementById(sSelect);
     //默认状态不是移动到顶端
     if(isToTop == null)
         var isToTop = false;
         
     //如果是多选------------------------------------------------------------------
     if(oSelect.multiple)
     {
         for(var selIndex=0; selIndex<oSelect.options.length; selIndex++)
         {
             //如果设置了移动到顶端标志
             if(isToTop)
             {
                 if(oSelect.options[selIndex].selected)
                 {
                     var transferIndex = selIndex;
                     while(transferIndex > 0 && !oSelect.options[transferIndex - 1].selected)
                     {
                         oSelect.options[transferIndex].swapNode(oSelect.options[transferIndex - 1]);
                         transferIndex --;
                     }
                 }
             }
             //没有设置移动到顶端标志
             else
             {
                 if(oSelect.options[selIndex].selected)
                 {
                     if(selIndex > 0)
                     {
                         if(!oSelect.options[selIndex - 1].selected)
                             oSelect.options[selIndex].swapNode(oSelect.options[selIndex - 1]);
                     }
                 }
             }
         }
     }
     //如果是单选--------------------------------------------------------------------
     else
     {
         var selIndex = oSelect.selectedIndex;
         if(selIndex <= 0)
             return;
         //如果设置了移动到顶端标志
         if(isToTop)
         {
             while(selIndex > 0)
             {
                 oSelect.options[selIndex].swapNode(oSelect.options[selIndex - 1]);
                 selIndex --;
             }
         }
         //没有设置移动到顶端标志
         else        
             oSelect.options[selIndex].swapNode(oSelect.options[selIndex - 1]);
     }
 }

 function moveDown(sSelect,isToBottom)
 {
     var oSelect = document.getElementById(sSelect);
     //默认状态不是移动到顶端
     if(isToBottom == null)
         var isToBottom = false;
         
     var selLength = oSelect.options.length - 1;
     
     //如果是多选------------------------------------------------------------------
     if(oSelect.multiple)
     {
         for(var selIndex=oSelect.options.length - 1; selIndex>= 0; selIndex--)
         {
             //如果设置了移动到顶端标志
             if(isToBottom)
             {
                 if(oSelect.options[selIndex].selected)
                 {
                     var transferIndex = selIndex;
                     while(transferIndex < selLength && !oSelect.options[transferIndex + 1].selected)
                     {
                         oSelect.options[transferIndex].swapNode(oSelect.options[transferIndex + 1]);
                         transferIndex ++;
                     }
                 }
             }
             //没有设置移动到顶端标志
             else
             {
                 if(oSelect.options[selIndex].selected)
                 {
                     if(selIndex < selLength)
                     {
                         if(!oSelect.options[selIndex + 1].selected)
                             oSelect.options[selIndex].swapNode(oSelect.options[selIndex + 1]);
                     }
                 }
             }
         }
     }
     //如果是单选--------------------------------------------------------------------
     else
     {
         var selIndex = oSelect.selectedIndex;
         if(selIndex >= selLength - 1)
             return;
         //如果设置了移动到顶端标志
         if(isToBottom)
         {
             while(selIndex < selLength - 1)
             {
                 oSelect.options[selIndex].swapNode(oSelect.options[selIndex + 1]);
                 selIndex ++;
             }
         }
         //没有设置移动到顶端标志
         else        
             oSelect.options[selIndex].swapNode(oSelect.options[selIndex + 1]);
     }
 }

 function moveSelected(sSourceSel,sTargetSel)
 {
      var oSourceSel = document.getElementById(sSourceSel);
      var oTargetSel = document.getElementById(sTargetSel);
     //建立存储value和text的缓存数组
     var arrSelValue = new Array();
     var arrSelText = new Array();
     //此数组存贮选中的options，以value来对应
     var arrValueTextRelation = new Array();
     var index = 0;//用来辅助建立缓存数组
     
     //存储源列表框中所有的数据到缓存中，并建立value和选中option的对应关系
     for(var i=0; i<oSourceSel.options.length; i++)
     {
         if(oSourceSel.options[i].selected)
         {
             //存储
             arrSelValue[index] = oSourceSel.options[i].value;
             arrSelText[index] = oSourceSel.options[i].text;
             //建立value和选中option的对应关系
             arrValueTextRelation[arrSelValue[index]] = oSourceSel.options[i];
             index ++;
         }
     }
     
     //增加缓存的数据到目的列表框中，并删除源列表框中的对应项
     for(var i=0; i<arrSelText.length; i++)  
     {
         //增加
         var oOption = document.createElement("option");
         oOption.text = arrSelText[i];
         oOption.value = arrSelValue[i];
         oTargetSel.add(oOption);
         //删除源列表框中的对应项
         oSourceSel.removeChild(arrValueTextRelation[arrSelValue[i]]);
     }
 }
function GetColumns()
{
    var objres = document.getElementById('eOfficeGridShowColumns');
    var result = 'Select#';
    for(var i = 0 ;i < objres.options.length;i++)
    {
        result += objres.options[i].value+';';
    }
    return result+'10';
}
function ShowSelectWindow()
{
    showMask("Grid_Select_Columns_Extension,选择列,280,160");
    var p = document.getElementById('Grid_Select_Columns_Extension');
    p.style.visibility = "visible";
    p.style.display = "block";
    var s = document.getElementById('eOfficeGridShowColumns');
    s.style.visibility = "visible";
    var h = document.getElementById('eOfficeGridHideColumns');
    h.style.visibility = "visible";
    
    //var o = document.getElementById('eOfficeGridShowColumns');
}

function HideSelectWindow()
{
    hideMask(false);
    var p = document.getElementById('Grid_Select_Columns_Extension');
    p.style.visibility = "hidden";
    p.style.display = "none";
    var s = document.getElementById('eOfficeGridShowColumns');
    s.style.visibility = "hidden";
    var h = document.getElementById('eOfficeGridHideColumns');
    h.style.visibility = "hidden";
    return false;
}

function GridSelectAll(obj)
{
debugger;
var theTable  = obj.parentElement.parentElement.parentElement;
var i;
var j = obj.parentElement.cellIndex;
for(i=0;i<theTable.rows.length;i++)
{
var objCheckBox = theTable.rows[i].cells[j].firstChild;
if(objCheckBox.checked!=null)objCheckBox.checked = obj.checked;
}
}

//点击行时高亮显示
function ClickRow(row){
    var o = row;
    if(o.className == "GridRow")
        o.className = "SelectedRow";
    var trs = o.parentNode.getElementsByTagName("TR");
    for(i=0;i<trs.length;i++){   
        if(o!=trs[i] && trs[i].className == "SelectedRow")trs[i].className = "GridRow";
    }
}

//获取选中的行(tr)
function GetSelectedRow(gridId)
{
    if(!document.getElementById(gridId)) return null;
    var trs = document.getElementById(gridId).getElementsByTagName("TR");
    if(!trs) return null;
    var i = 0;
    for(i=0;i<trs.length;i++){if(trs[i].className == "SelectedRow") return trs[i];}
    return null;
}

//以数组形式返回选中行中数据，若无选择则返回null
function GetDataFromSelectedRow(gridId){var tr = GetSelectedRow(gridId);if(tr==null) return null;var tds = tr.getElementsByTagName("TD");if(!tds) return null;var items = new Array();for(i=0;i<tds.length;i++){items[i] = tds[i].innerText;}return items;}